#include <vector>
#include <map>
#include <iostream>
#include <functional>
#include <algorithm>
using namespace std;
class Solution {
public:
    int thirdMax(vector<int>& nums) {
		if (nums.size() < 3)
			return *max_element(nums.begin(), nums.end());
		map<int, int,greater<int>> iv;
		for (auto i = 0; i < nums.size(); ++i)
		{
			iv.insert({ nums[i],nums[i] });
		}		
		if (iv.size() < 3)
			return iv.begin()->second;
		auto it = iv.begin();
		++it;
		++it;
		return it->second;        
    }
};
int main()
{
	cout<<Solution().thirdMax(vector<int>({ 2,3,1,2 }));
}
